package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.mapper.OrderSettingListMapper;
import com.itheima.service.OrderSettingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service(interfaceClass = OrderSettingListService.class)
@Transactional
public class OrderSettingListServiceImpl implements OrderSettingListService {
    @Autowired
    private OrderSettingListMapper orderSettingListMapper;
    @Override
    public PageResult findPage(Map map) {

        Integer pageSize = (Integer) map.get("pageSize");
        Integer currentPage = (Integer) map.get("currentPage");
        String queryString = (String) map.get("queryString");
        String orderType = (String) map.get("orderType");
        String orderStatus =(String) map.get("orderStatus");
        PageHelper.startPage(currentPage, pageSize);
        Page<Map<String,Object>> orderSettingList=null;
        if(((String)map.get("startDate"))!=null){
            orderSettingList=orderSettingListMapper.selectByTime((String)map.get("startDate"),(String)map.get("endDate"));
        }else{
            if(queryString!=null){
                orderSettingList = orderSettingListMapper.selectByCondition(queryString);
            }else if(orderType==null){
                orderSettingList = orderSettingListMapper.selectByCondition(orderStatus);
            }else {
                orderSettingList = orderSettingListMapper.selectByCondition(orderType);
            }
        }

        long total = orderSettingList.getTotal();
        List<Map<String,Object>> result = orderSettingList.getResult();
        return new PageResult(total, result);
    }
}
